﻿using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Xml.Linq;
using Weather.UA.Model;

namespace Weather.UA
{
    public partial class WeatherUA : IWeatherUA
    {
        public WeatherUA(Language language = Language.en, string userID = null)
        {
            Language = language;
            UserId = userID;
            ApiDomain = Settings.ApiUrl;
            ApiVersion = Settings.ApiVersion;

            _sector = new Sector();
            _sectors = new List<Sector>();

            _country = new Country();
            _countries = new List<Country>();

            _city = new City();
            _cities = new List<City>();
        }

        public string ApiDomain { get; private set; }
        public string ApiVersion { get; private set; }
        public string UserId { get; private set; }
        public Language Language { get; private set; }

        private XDocument _loadXDocument(string url)
        {
            if (UserId != null)
                url += "&userid=" + UserId;
            var result = new XDocument();
            using (var client = new HttpClient())
            {
                var response = client.GetAsync(url);
                if (response.Result.IsSuccessStatusCode)
                {
                    result = XDocument.Parse(response.Result.Content.ReadAsStringAsync().Result);
                }

            }
            return result;
        }
    }
}
